// JScript File
/** Scripts for the ValuePicker control */

function decreaseMini(cid, minvalue)
{
    v = parseInt(document.getElementById(cid).value);
    if(isNaN(v))
    {
        v = minvalue;
    }
    if(v > minvalue)
    {
        document.getElementById(cid).value = v - 1;
    }
}

function decreaseMiniBy10(cid, minvalue)
{
    v = parseInt(document.getElementById(cid).value);
    if(isNaN(v))
    {
        v = minvalue;
    }
    if(v > minvalue + 10)
    {
        document.getElementById(cid).value = v - 10;
    }
    else
    {
        document.getElementById(cid).value = minvalue;
    }
}

function increaseMini(cid, maxvalue)
{
    v = parseInt(document.getElementById(cid).value);
    if(isNaN(v))
    {
        v = maxvalue;
    }
    if(v < maxvalue)
    {
        document.getElementById(cid).value = v + 1;
    }
}

function increaseMiniBy10(cid, maxvalue)
{
    v = parseInt(document.getElementById(cid).value);
    if(isNaN(v))
    {
        v = maxvalue;
    }
    if(v < maxvalue - 10)
    {
        document.getElementById(cid).value = v + 10;
    }
    else
    {
        document.getElementById(cid).value = maxvalue;
    }
}

function blurMini(cid, minvalue, maxvalue, defaultvalue)
{
    v = parseInt(document.getElementById(cid).value);
    if (isNaN(v) || v.toString().length != document.getElementById(cid).value.length)
    {
        document.getElementById(cid).value = defaultvalue;
    }
    else if(v < minvalue)
    {
        document.getElementById(cid).value = minvalue;
    }
    else if(v > maxvalue)
    {
        document.getElementById(cid).value = maxvalue;
    }
    
}

function KeyPressMini(e, cid, minvalue, maxvalue)
{
    keynum = e.which ? e.which : e.keyCode;
    if(keynum == 38 || keynum == 40)
    {
        if(keynum == 38)
        {
            increaseMini(cid, maxvalue);
        }
        else if(keynum == 40)
        {
            decreaseMini(cid, minvalue);
        }
        
        element = document.getElementById(cid);
        v = parseInt(element.value);
        if(v > maxvalue)
        {
            element.value = maxvalue;
        }
        else if(v < minvalue)
        {
            element.value = minvalue;
        }
    }
    return !(keynum > 31 && (keynum < 48 || keynum > 57)) || keynum == 37 ||keynum == 38 || 
        keynum == 39 || keynum == 40 || keynum == 45 || keynum == 46;
}
